package com.imooc.sell.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

public class SHA1Util {

	private static final String token = "wuxb";
	public static boolean getStrBySHA1(String signature,String timestamp,String nonce) {
		String[] arr = new String[]{token,timestamp,nonce};
		Arrays.sort(arr);
		
		StringBuffer buffer = new StringBuffer();
		for (String string : arr) {
			buffer.append(string);
		}
		String sha1 = SHA1Digest(buffer.toString());
		return sha1.equals(signature);
	}
	
	 public static String SHA1Digest(String text) {
	    	String pwd = "";
			try {
				MessageDigest md = MessageDigest.getInstance("SHA1");
				md.update(text.getBytes());
				pwd = new BigInteger(1, md.digest()).toString(16); 
			} catch (NoSuchAlgorithmException e) {
				e.printStackTrace();
			}
	    	return pwd;
	    }
}
